<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>CTF实验环境管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			var answerType="${sceneCtfEnvironment.answerType}";
			var increaseTimeAllow="${sceneCtfEnvironment.increaseTimeAllow}";
			var ctfType="${sceneCtfEnvironment.ctfType}";

			$(document).ready(function() {

				$("#inputForm").validate({
					rules: {
						port: {
							required: false,
							digits: true
						}
					}
				});
			});
			if(answerType=='0')
			{
				$("#fixedAnswerDiv").show();
				$("#autoAnswer").hide();

			}else{
				$("#fixedAnswerDiv").hide();
				$("#autoAnswer").show();
			}
			if(increaseTimeAllow=='0')
			{
				$("#addTimeDiv").show();

			}else{
				$("#addTimeDiv").hide();

			}
			if(ctfType=='0')
			{
				$("#portCtfType").hide();

			}
		});


		function timeAllowChoose(selete)
		{
			var option=selete.options[selete.selectedIndex].value;
			if(option==0)
			{
				$("#addTimeDiv").show();

			}else{
				$("#addTimeDiv").hide();

			}

		}
		function answerTypeChoose(selete)
		{
			var option=selete.options[selete.selectedIndex].value;
			if(option==0)
			{
				$("#fixedAnswerDiv").show();
				$("#autoAnswer").hide();

			}else{
				$("#fixedAnswerDiv").hide();
				$("#autoAnswer").show();
			}

		}
		function ctfTypeChoose(selete)
		{
			var option=selete.options[selete.selectedIndex].value;
			if(option==0)
			{
				$("#portCtfType").hide();

			}else{
				$("#portCtfType").show();
			}

		}
		function checkValidate()
		{
			var ctfEnvironmentName=document.getElementById("ctfEnvironmentName").value;


			var ctfEnvironmentTimeSelect=document.getElementById("ctfEnvironmentTime");
			var ctfEnvironmentTimeOption=ctfEnvironmentTimeSelect.options[ctfEnvironmentTimeSelect.selectedIndex].value;

			var increaseTimeAllowSelect=document.getElementById("increaseTimeAllow");
			var increaseTimeAllowOption=increaseTimeAllowSelect.options[increaseTimeAllowSelect.selectedIndex].value;

			var increaseTimeSelect=document.getElementById("increaseTime");
			var increaseTimeOption=increaseTimeSelect.options[increaseTimeSelect.selectedIndex].value;

			var increaseNumberSelect=document.getElementById("increaseNumber");
			var increaseNumberOption=increaseNumberSelect.options[increaseNumberSelect.selectedIndex].value;

			var ctfTypeSelect=document.getElementById("ctfType");
			var ctfTypeOption=ctfTypeSelect.options[ctfTypeSelect.selectedIndex].value;

			var answerTypeSelect=document.getElementById("answerType");
			var answerTypeOption=answerTypeSelect.options[answerTypeSelect.selectedIndex].value;

			var account=document.getElementById("account").value;
			var password=document.getElementById("password").value;
			var fixedAnswer=document.getElementById("fixedAnswer").value;
			var port=document.getElementById("port").value;
			var ip=document.getElementById("ip").value;



			//判断是否为空
			if(ctfEnvironmentName==null||ctfEnvironmentName=="")
			{
				window.alertx("请输入实验名称！");
				return false;
			}
			if(ctfEnvironmentTimeOption==null||ctfEnvironmentTimeOption=="")
			{
				window.alertx("请选择实验时间！");
				return false;
			}
			if(increaseTimeAllowOption==0)
			{
				if(increaseTimeOption==null||increaseTimeOption=="")
				{
					window.alertx("请选择每次增加的时间！");
					return false;
				}
				if(increaseNumberOption==null||increaseNumberOption=="")
				{
					window.alertx("请选择增加的次数！");
					return false;
				}
			}
			if(answerTypeOption==1)
			{
				if(account==null||account=="")
				{
					window.alertx("请输入账户名！");
					return false;
				}
				if(password==null||password=="")
				{
					window.alertx("请输入密码！");
					return false;
				}
			}else{
				if(fixedAnswer==null||fixedAnswer=="")
				{
					window.alertx("请输入固定答案！");
					return false;
				}
			}


			if(ctfTypeOption==1)
			{
				if(ip==null||ip=="")
				{
					window.alertx("请输入IP！");
					return false;
				}
				if(port==null||port=="")
				{
					window.alertx("请输入端口！");
					return false;
				}
			}


		}
	</script>
</head>
<body>
<ul class="nav nav-tabs">
	<li><a href="${ctx}/scene/sceneCtfEnvironment/">CTF实验环境列表</a></li>
	<li class="active"><a href="${ctx}/scene/sceneCtfEnvironment/form?id=${sceneCtfEnvironment.id}">CTF实验环境<shiro:hasPermission name="scene:sceneCtfEnvironment:edit">${not empty sceneCtfEnvironment.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="scene:sceneCtfEnvironment:edit">查看</shiro:lacksPermission></a></li>
</ul><br/>
<form:form id="inputForm" modelAttribute="sceneCtfEnvironment" action="${ctx}/scene/sceneCtfEnvironment/topology" method="post" class="form-horizontal">
	<form:hidden path="id"/>
	<sys:message content="${message}"/>
	<div class="control-group">
		<label class="control-label">实验名称：</label>
		<div class="controls">
			<form:input path="ctfEnvironmentName" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
			<span class="help-inline"><font color="red">*</font> </span>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">实验类型：</label>
		<div class="controls">

			<select id="ctfEnvironmentType" name="ctfEnvironmentType" class="input-large required">


				<c:choose>
					<c:when test="${isSuperAdmin=='false'}">
						<option value="0" selected>${fns:getDictLabel("0",'scene_env_type',"无")}</option>
					</c:when>
					<c:otherwise>
						<c:forEach var="attribute" items="${fns:getDictList('scene_env_type')}">
							<option value="${fns:getDictValue(attribute,'scene_env_type',"")}" <c:if test="${fns:getDictValue(attribute,'scene_env_type','')==sceneEnvironment.environmentType}">selected</c:if>>${attribute}</option>
						</c:forEach>
					</c:otherwise>
				</c:choose>


			</select>
			<span class="help-inline"><font color="red">*</font> </span>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">实验时间：</label>
		<div class="controls">
			<select id="ctfEnvironmentTime" name="ctfEnvironmentTime" path="ctfEnvironmentTime" class="input-large required">
				<c:forEach var="attribute" items="${fns:getDictList('scene_env_time')}">
					<option value="${fns:getDictValue(attribute,'scene_env_time',"")}" <c:choose><c:when test="${sceneCtfEnvironment.ctfEnvironmentTime==null||sceneCtfEnvironment.ctfEnvironmentTime==''}"><c:if test="${fns:getDictValue(attribute,'scene_env_time','')==3}">selected</c:if></c:when><c:otherwise><c:if test="${fns:getDictValue(attribute,'scene_env_time','')==sceneCtfEnvironment.ctfEnvironmentTime}">selected</c:if></c:otherwise></c:choose>>${attribute}</option>
				</c:forEach>
			</select>
			<span class="help-inline"><font color="red">*</font> </span>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">标签：</label>
		<div class="controls">
			<form:input path="label" htmlEscape="false" maxlength="64" class="input-xlarge "/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">是否允许增加实验时间：</label>
		<div class="controls">
			<select id="increaseTimeAllow" name="increaseTimeAllow" onchange="timeAllowChoose(this)" class="input-large">

				<option value="1" <c:if test="${sceneCtfEnvironment.increaseTimeAllow=='1'}">selected</c:if>>否</option>
				<option value="0" <c:if test="${sceneCtfEnvironment.increaseTimeAllow=='0'}">selected</c:if>>是</option>
			</select>
		</div>
	</div>
	<div id="addTimeDiv" hidden>

		<div class="control-group">
			<label class="control-label">每次增加时间：</label>
			<div class="controls">
				<form:select path="increaseTime" class="input-large ">
					<form:option value="" label="">===请选择===</form:option>
					<form:options items="${fns:getDictList('scene_env_increase_time')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">增加次数：</label>
			<div class="controls">
				<form:select path="increaseNumber" class="input-large ">
					<form:option value="" label="">===请选择===</form:option>
					<form:options items="${fns:getDictList('scene_env_increase_number')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">实验答案类型：</label>
		<div class="controls">
			<select id="answerType" name="answerType" onchange="answerTypeChoose(this)" class="input-large">
				<option value="1" <c:if test="${sceneCtfEnvironment.answerType=='1'}">selected</c:if>>自动</option>
				<option value="0" <c:if test="${sceneCtfEnvironment.answerType=='0'}">selected</c:if>>固定</option>
			</select>
		</div>
	</div>
	<div id="autoAnswer" >
		<div class="control-group">
			<label class="control-label">账户名：</label>
			<div class="controls">
				<form:input path="account" htmlEscape="false" maxlength="64" class="input-xlarge"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\u4e00-\u9fa5]/g,''))" onkeyup="this.value=this.value.replace(/[\u4e00-\u9fa5]/g,'')" />
			</div>
		</div>
		<div class="control-group" >
			<label class="control-label">密码：</label>
			<div class="controls">
				<form:input path="password" htmlEscape="false" maxlength="64" class="input-xlarge"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\u4e00-\u9fa5]/g,''))" onkeyup="this.value=this.value.replace(/[\u4e00-\u9fa5]/g,'')" />
			</div>
		</div>
	</div>
	<div class="control-group" id="fixedAnswerDiv" hidden>
		<label class="control-label">固定答案：</label>
		<div class="controls">
			<form:textarea path="fixedAnswer" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">CTF类型：</label>
		<div class="controls">
			<select id="ctfType" name="ctfType" onchange="ctfTypeChoose(this)" class="input-large">
				<option value="1" <c:if test="${sceneCtfEnvironment.ctfType=='1'}">selected</c:if>>端口型</option>
				<option value="0" <c:if test="${sceneCtfEnvironment.ctfType=='0'}">selected</c:if>>web应用型</option>
			</select>

		</div>
	</div>
	<div id="portCtfType" >
		<div class="control-group">
			<label class="control-label">IP：</label>
			<div class="controls">
				<form:input path="ip" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">端口：</label>
			<div class="controls">
				<form:input id="port" name="port" path="port" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
	</div>
	<div class="form-actions">
		<shiro:hasPermission name="scene:sceneCtfEnvironment:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" onclick=" return checkValidate()" value="下一步"/>&nbsp;</shiro:hasPermission>
		<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
	</div>
</form:form>
</body>
</html>